<?php

namespace App\Jobs\QiPao\Group;

use App\Jobs\Job;
use App\Traits\Elasticsearch;
use Elasticsearch\Client;
use Illuminate\Support\Facades\Log;

class GroupMatchChangeStatusJob extends Job
{
    use Elasticsearch;

    protected $userId;
    protected $fields;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($userId, $fields)
    {
        $this->userId = $userId;
        $this->fields = $fields;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try {
            $index = config("elasticsearch.index.match");

            //将对方用户设置为今日匹配过了
            $updateIndexParams = [
                "id"    => $this->userId,
                "index" => $index,
                "type"  => '_doc',
                "body"  => ['doc' => $this->fields],
            ];
            Log::info('修改匹配状态：' . json_encode($updateIndexParams));
            /** @var Client $elasticSearch */
            $elasticSearch = self::getElasticsearchInstance();
            $elasticSearch->update($updateIndexParams);


        } catch (\Exception $e) {
            Log::error('修改匹配状态错误：' . $e->getMessage());
        }
    }

    /* public function fail($exception = null )
     {
         Log::error('giftJob:'.$exception->getMessage());
     }*/
}
